package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.user.UserDO;
import com.qk.dto.user.UserDTO;
import com.qk.entity.User;
import com.qk.management.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: chouh
 * @DateTime: 2025/10/7 21:03
 * @Description:
 */

@Slf4j
@RestController
@RequestMapping("/users")
@SuppressWarnings("all")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public Result queryAllUsers(){
        log.info("queryAllUsers");
        List<User> result = userService.queryAllUsers();
        return Result.success(result);
    }

    @PutMapping
    public Result updateUser(@RequestBody User user) {
        log.info("updateUser:{}",user);
        userService.updateUser(user);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryUserById(@PathVariable("id")Integer id){
        log.info("queryUserById:{}", id);
        UserDO user = userService.queryUserById(id);
        return Result.success(user);
    }

    @DeleteMapping("/{ids}")
    public Result deleteUser(@PathVariable("ids")List<Integer> ids){
        log.info("deleteUser:{}", ids);
        userService.deleteUsers(ids);
        return Result.success();
    }
    @PostMapping
    public Result addUser(@RequestBody User user) {
        log.info("addUser:{}", user);
        userService.addUser(user);
        return Result.success();
    }

    @GetMapping
    public Result getUsers(UserDTO userDTO) {
        log.info("getUsers:{}", userDTO);
        PageResult<UserDO> result = userService.getUsers(userDTO);
        return Result.success(result);
    }
}
